{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:35:56.628130Z",
     "start_time": "2019-03-20T09:35:45.661384Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator\\Anaconda3\\lib\\requests\\__init__.py:80: RequestsDependencyWarning: urllib3 (1.25.11) or chardet (3.0.4) doesn't match a supported version!\n",
      "  RequestsDependencyWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "matchzoo version 1.0.2\n",
      "`ranking_task` initialized with metrics [normalized_discounted_cumulative_gain@3(0.0), normalized_discounted_cumulative_gain@5(0.0), mean_average_precision(0.0)]\n",
      "data loading ...\n",
      "data loaded as `train_pack_raw` `dev_pack_raw` `test_pack_raw`\n",
      "停用表配置成功\n"
     ]
    }
   ],
   "source": [
    "%run init.ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:35:56.633000Z",
     "start_time": "2019-03-20T09:35:56.630450Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "preprocessor = mz.models.ArcII.get_default_preprocessor(\n",
    "    filter_mode='df',\n",
    "    filter_low_freq=1,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:36:06.249211Z",
     "start_time": "2019-03-20T09:35:56.634788Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval:   0%| | 0/97 [00:00<?, ?it/s]Building prefix dict from the default dictionary ...\n",
      "Loading model from cache C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\jieba.cache\n",
      "Loading model cost 1.482 seconds.\n",
      "Prefix dict has been built succesfully.\n",
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 97/97 [00:02<00:00, 45.10it/s]\n",
      "Processing text_right with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 95/95 [00:00<00:00, 135.41it/s]\n",
      "Processing text_right with append: 100%|████████████████████████████████████████████| 95/95 [00:00<00:00, 47526.11it/s]\n",
      "Building FrequencyFilter from a datapack.: 100%|████████████████████████████████████| 95/95 [00:00<00:00, 31709.29it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 95/95 [00:00<00:00, 23774.40it/s]\n",
      "Processing text_left with extend: 100%|█████████████████████████████████████████████| 97/97 [00:00<00:00, 32312.56it/s]\n",
      "Processing text_right with extend: 100%|████████████████████████████████████████████| 95/95 [00:00<00:00, 23831.27it/s]\n",
      "Building Vocabulary from a datapack.: 100%|██████████████████████████████████████| 841/841 [00:00<00:00, 840059.46it/s]\n",
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 97/97 [00:00<00:00, 127.04it/s]\n",
      "Processing text_right with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 95/95 [00:00<00:00, 141.87it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 95/95 [00:00<00:00, 23764.47it/s]\n",
      "Processing text_left with transform: 100%|██████████████████████████████████████████| 97/97 [00:00<00:00, 24248.87it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 95/95 [00:00<00:00, 11886.13it/s]\n",
      "Processing length_left with len: 100%|██████████████████████████████████████████████| 97/97 [00:00<00:00, 13852.96it/s]\n",
      "Processing length_right with len: 100%|█████████████████████████████████████████████| 95/95 [00:00<00:00, 23788.59it/s]\n",
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 44/44 [00:00<00:00, 104.08it/s]\n",
      "Processing text_right with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 49/49 [00:00<00:00, 133.23it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 49/49 [00:00<00:00, 16346.21it/s]\n",
      "Processing text_left with transform: 100%|██████████████████████████████████████████| 44/44 [00:00<00:00, 22027.86it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 49/49 [00:00<00:00, 16329.33it/s]\n",
      "Processing length_left with len: 100%|██████████████████████████████████████████████| 44/44 [00:00<00:00, 44097.82it/s]\n",
      "Processing length_right with len: 100%|█████████████████████████████████████████████| 49/49 [00:00<00:00, 49062.04it/s]\n",
      "Processing text_left with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 28/28 [00:00<00:00, 149.02it/s]\n",
      "Processing text_right with chain_transform of ChineseRemoveBlack => ChineseSimplified => ChineseEmotion => IsChinese => ChineseStopRemoval => ChineseTokenizeDemo => Tokenize => Lowercase => PuncRemoval: 100%|█| 29/29 [00:00<00:00, 144.36it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 29/29 [00:00<00:00, 14516.63it/s]\n",
      "Processing text_left with transform: 100%|██████████████████████████████████████████| 28/28 [00:00<00:00, 13989.34it/s]\n",
      "Processing text_right with transform: 100%|█████████████████████████████████████████| 29/29 [00:00<00:00, 14495.87it/s]\n",
      "Processing length_left with len: 100%|██████████████████████████████████████████████| 28/28 [00:00<00:00, 27942.07it/s]\n",
      "Processing length_right with len: 100%|█████████████████████████████████████████████| 29/29 [00:00<00:00, 29057.53it/s]\n"
     ]
    }
   ],
   "source": [
    "train_pack_processed = preprocessor.fit_transform(train_pack_raw)\n",
    "dev_pack_processed = preprocessor.transform(dev_pack_raw)\n",
    "test_pack_processed = preprocessor.transform(test_pack_raw)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:36:06.262937Z",
     "start_time": "2019-03-20T09:36:06.253350Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'embedding_input_dim': 325,\n",
       " 'filter_unit': <mzcn.preprocessors.units.frequency_filter.FrequencyFilter at 0x1adc069fac8>,\n",
       " 'vocab_size': 325,\n",
       " 'vocab_unit': <mzcn.preprocessors.units.vocabulary.Vocabulary at 0x1adce24ac50>}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "preprocessor.context"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 由于加载glove模型会导致本案例运行速度会变慢，所以不加载glove模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# glove_embedding = mz.datasets.embeddings.load_glove_embedding(dimension=100)\n",
    "# term_index = preprocessor.context['vocab_unit'].state['term_index']\n",
    "# embedding_matrix = glove_embedding.build_matrix(term_index)\n",
    "# l2_norm = np.sqrt((embedding_matrix * embedding_matrix).sum(axis=1))\n",
    "# embedding_matrix = embedding_matrix / l2_norm[:, np.newaxis]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "trainset = mz.dataloader.Dataset(\n",
    "    data_pack=train_pack_processed,\n",
    "    mode='pair',\n",
    "    num_dup=2,\n",
    "    num_neg=1\n",
    ")\n",
    "devset = mz.dataloader.Dataset(\n",
    "    data_pack=dev_pack_processed\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "padding_callback = mz.models.ArcII.get_default_padding_callback(\n",
    "    fixed_length_left=10,\n",
    "    fixed_length_right=100,\n",
    "    pad_word_value=0,\n",
    "    pad_word_mode='pre'\n",
    ")\n",
    "\n",
    "trainloader = mz.dataloader.DataLoader(\n",
    "    dataset=trainset,\n",
    "    stage='train',\n",
    "    callback=padding_callback,\n",
    ")\n",
    "devloader = mz.dataloader.DataLoader(\n",
    "    dataset=devset,\n",
    "    stage='dev',\n",
    "    callback=padding_callback,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:36:06.413530Z",
     "start_time": "2019-03-20T09:36:06.267256Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ArcII(\n",
      "  (embedding): Embedding(325, 100, padding_idx=0)\n",
      "  (conv1d_left): Sequential(\n",
      "    (0): ConstantPad1d(padding=(0, 2), value=0)\n",
      "    (1): Conv1d(100, 32, kernel_size=(3,), stride=(1,))\n",
      "  )\n",
      "  (conv1d_right): Sequential(\n",
      "    (0): ConstantPad1d(padding=(0, 2), value=0)\n",
      "    (1): Conv1d(100, 32, kernel_size=(3,), stride=(1,))\n",
      "  )\n",
      "  (matching): Matching()\n",
      "  (conv2d): Sequential(\n",
      "    (0): Sequential(\n",
      "      (0): ConstantPad2d(padding=(0, 2, 0, 2), value=0)\n",
      "      (1): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1))\n",
      "      (2): ReLU()\n",
      "      (3): MaxPool2d(kernel_size=(3, 3), stride=(3, 3), padding=0, dilation=1, ceil_mode=False)\n",
      "    )\n",
      "    (1): Sequential(\n",
      "      (0): ConstantPad2d(padding=(0, 2, 0, 2), value=0)\n",
      "      (1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1))\n",
      "      (2): ReLU()\n",
      "      (3): MaxPool2d(kernel_size=(3, 3), stride=(3, 3), padding=0, dilation=1, ceil_mode=False)\n",
      "    )\n",
      "  )\n",
      "  (dropout): Dropout(p=0.3, inplace=False)\n",
      "  (out): Linear(in_features=704, out_features=1, bias=True)\n",
      ")\n",
      "Trainable params:  107893\n"
     ]
    }
   ],
   "source": [
    "model = mz.models.ArcII()\n",
    "\n",
    "model.params['task'] = ranking_task\n",
    "# model.params['embedding'] = embedding_matrix #这里是当加载glove等模型时取消该行注释\n",
    "#设置embedding系数\n",
    "model.params[\"embedding_output_dim\"]=100\n",
    "model.params[\"embedding_input_dim\"]=preprocessor.context[\"embedding_input_dim\"]\n",
    "model.params['left_length'] = 10\n",
    "model.params['right_length'] = 100\n",
    "model.params['kernel_1d_count'] = 32\n",
    "model.params['kernel_1d_size'] = 3\n",
    "model.params['kernel_2d_count'] = [64, 64]\n",
    "model.params['kernel_2d_size'] = [(3, 3), (3, 3)]\n",
    "model.params['pool_2d_size'] = [(3, 3), (3, 3)]\n",
    "model.params['dropout_rate'] = 0.3\n",
    "\n",
    "model.build()\n",
    "\n",
    "print(model)\n",
    "print('Trainable params: ', sum(p.numel() for p in model.parameters() if p.requires_grad))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:36:06.422264Z",
     "start_time": "2019-03-20T09:36:06.415605Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3554df0d0fd540488cd3a06b4ae8541a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-1 Loss-1.001]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "bae79dc000ad4adc8da2b2c39dc56ccd",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-2 Loss-0.945]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6a1dd54ddded4296a21eb4867b123f03",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-3 Loss-0.961]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "468587053cb04735a563897caec21fee",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-4 Loss-0.979]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fd3ebc860e1f4dc78bbae6dbb6bf43d8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-5 Loss-0.794]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fc54a026cfac46b6907066747c18e974",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-6 Loss-0.728]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ed8f8cd6793e4020bca5fb3952bbbb6a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-7 Loss-0.679]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3bfa92ca65cb45ef9e3ba93cbf12a148",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-8 Loss-0.523]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2e8eba83923c4a2883c8521fc8c3b432",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-9 Loss-0.559]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d8b33e616745452193de8fd26f2c950e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-10 Loss-0.466]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d54a75bc7b1d499aad0277e33679d8f6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-11 Loss-0.356]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cb8fe9e0974846d7acd1b462792d2b79",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-12 Loss-0.337]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8a436528d5514890912c00db61886c88",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-13 Loss-0.179]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1160a3a7436c41699c2c4e8ae6eac375",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-14 Loss-0.256]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "07f54ea741424a4eb429bc872b8a928e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Iter-15 Loss-0.018]:\n",
      "  Validation: normalized_discounted_cumulative_gain@3(0.0): 0.25 - normalized_discounted_cumulative_gain@5(0.0): 0.25 - mean_average_precision(0.0): 0.25\n",
      "\n",
      "Cost time: 9.7664053440094s\n"
     ]
    }
   ],
   "source": [
    "optimizer = torch.optim.Adam(model.parameters(), lr = 3e-4)\n",
    "\n",
    "trainer = mz.trainers.Trainer(\n",
    "    model=model,\n",
    "    optimizer=optimizer,\n",
    "    trainloader=trainloader,\n",
    "    validloader=devloader,\n",
    "    validate_interval=None,\n",
    "    epochs=15\n",
    ")\n",
    "\n",
    "trainer.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "648"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import gc\n",
    "gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
